package vm.machine;

public class AddInstruction extends  AbstractInstruction{

    String register1;
    Object register2;
    public AddInstruction(Machine machine,String register1, Object register2){
        super(machine);
        this.machine = machine;
        this.register1 = register1;
        this.register2 = register2;
    }

    @Override
    public void doAction() {
        Register reg1 = machine.getRegister(register1);
        if(register2 instanceof String){
            reg1.setValue(reg1.getValue() + machine.getRegister((String) register2).getValue());
        }else{
            reg1.setValue(reg1.getValue() + (Integer) register2);
        }
    }

    @Override
    public String toString() {
        return "执行Add指令";
    }
}
